<%@tag import="java.util.List"%>
<%@tag import="by.epam.communalservices.entity.JkhTeam"%>
<%@tag import="by.epam.communalservices.utils.Staff"%>
<%@tag import="java.sql.Connection"%>
<%@ attribute name="id" required="true"%>
<%@ attribute name="add" required="true"%>
<%@ attribute name="remove" required="true"%>
<%@ attribute name="append" required="true"%>
<%
    request.setAttribute("team", false);

    try {
        if (getJspContext().getAttribute("id") != ""
                && Long.parseLong(getJspContext().getAttribute("id").toString()) > 0) {
            request.setAttribute("team", true);
            Connection con = (Connection) request.getSession().getAttribute("currentConnection");
            Staff staff = new Staff(con);
            if (getJspContext().getAttribute("append") != "") {
                if (getJspContext().getAttribute("add") != ""
                        && Long.parseLong(getJspContext().getAttribute("add").toString()) > 0) {
                    staff.addWorkerStaff(Long.parseLong(getJspContext().getAttribute("id").toString()),
                            Long.parseLong(getJspContext().getAttribute("add").toString()));
                    request.setAttribute("message", "Staff added");
                }
            } else if (getJspContext().getAttribute("remove") != ""
                    && Long.parseLong(getJspContext().getAttribute("remove").toString()) > 0) {
                staff.removeWorkerStaff(Long.parseLong(getJspContext().getAttribute("id").toString()),
                        Long.parseLong(getJspContext().getAttribute("remove").toString()));
                request.setAttribute("message", "Staff removed");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.println(e.getMessage() + "<br>");
        for (StackTraceElement el : e.getStackTrace()) {
            out.println(el.toString() + "<br>");
        }
    }
%>